<?php
/**
 * Created by PhpStorm.
 * User: zhangxinke
 * Date: 2019/6/6
 * Time: 0:16
 */
namespace app\api\controller;

use app\api\model\UnderlineModel;

class Underline extends BaseController
{
    public function __construct()
    {
        parent::__construct();
        $this->underline = new UnderlineModel();
    }
    public function index()
    {
        $data = $this->underline->select();
        foreach ($data as $key=>$val)
        {
            $url='http://restapi.amap.com/v3/geocode/geo?address='.$val['address'].'&key=541728fa8ac549c8aa84f683096b2dd4';
            if($result=file_get_contents($url))
            {
                $result = json_decode($result,true);
                //判断是否成功
                if(!empty($result['count'])){
                    $results = explode(',',$result['geocodes']['0']['location']);
                }
            }
            $data[$key]['latitude']=$results[1];
            $data[$key]['longitude']=$results[0];
        }
        if($data)
        {
            AjaxReturn('1','成功',$data);
        }else{
            AjaxReturn('0','失败');
        }
    }
}